/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.administrador.coordinadores;

import DBMS.DataBaseManager;
import clases.Coordinador;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author tamerdark
 */
public class Agregar extends DispatchAction {
    
//    private String PAGE1 = "page1";
    private String PAGE = "page";
    private String SUCCESS = "success";
    private String FAILURE = "failure";
    
    
    public ActionForward save(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Coordinador c = (Coordinador) form;
        DataBaseManager dbms = DataBaseManager.getInstance();
        System.out.println("La cedula del coordinador en agregar es: " + c.getCedula());
        if (dbms.agregarCoordinador(c)) {
            c.setMensaje("Coordinador agregado");
            return mapping.findForward(SUCCESS);
        } else {
            c.setMensaje("No se pudo agregar el Coordinador");
            return mapping.findForward(FAILURE);
        }
    }
    
    public ActionForward page(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
            return mapping.findForward(PAGE);
    }
//    
//    public ActionForward page2(ActionMapping mapping, ActionForm form,
//            HttpServletRequest request, HttpServletResponse response)
//            throws Exception {
//        request.setAttribute("instituciones", Institucion.getAll());
//        return mapping.findForward(PAGE2);
//    }
//    
//    public ActionForward page1(ActionMapping mapping, ActionForm form,
//            HttpServletRequest request, HttpServletResponse response)
//            throws Exception {
//        return mapping.findForward(PAGE1);
//    }
//    
//    public ActionForward populate(ActionMapping mapping, ActionForm form,
//            HttpServletRequest request, HttpServletResponse response)
//            throws Exception {
//        Coordinador c = (Coordinador) form;
//        Institucion i = new Institucion();
//        i.setId(c.getInstitucionId());
//        c.agregarInstitucion(i);
//        return mapping.findForward(PAGE2);
//    }
}
